package cn.mdmbct.douyin.spring.example.controller;

import cn.mdmbct.douyin.basis.response.user.*;
import cn.mdmbct.douyin.basis.service.interfaces.DyBasisService;
import cn.mdmbct.douyin.common.bean.PageCount;
import cn.mdmbct.douyin.common.enums.ApiPlatform;
import cn.mdmbct.douyin.common.bean.AccessToken;
import cn.mdmbct.douyin.common.bean.RefreshToken;
import cn.mdmbct.douyin.common.response.auth.AccessTokenRes;
import cn.mdmbct.douyin.common.storage.DyStorageManager;
import cn.mdmbct.douyin.spring.example.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author mdmbct  mdmbct@outlook.com
 * @date 2021/3/11 15:29
 * @modified mdmbct
 * @since 1.0
 */
@RestController
@RequestMapping("/dy/user")
@Api(tags = "抖音用户")
public class DyUserController {

    @Resource
    private DyBasisService dyBasisService;

    @Resource
    private DyStorageManager storageManager;

    @ApiOperation("保存token")
    @GetMapping("/access_token/save")
    public Result<?> saveToken() {

        storageManager.saveAccessToken("f1bc0c01-4009-46b2-a24c-a7ae9fba67bd", new AccessToken(1616383034338L, 1296000000L, "act.fbc5367e0ef1ce4d6ad3da335c24f490jkWPUm7Fime8ADpShmx4mL7RfTPq"));
        storageManager.saveRefreshToken("f1bc0c01-4009-46b2-a24c-a7ae9fba67bd", new RefreshToken(1616044374756L, 2592000000L, "rft.627d1cc73d7b29a7a81ee72e4001bd38212MCD3EF4Fz7Vlzr5WdJv4P97b5"));

        return Result.success();
    }

    @ApiOperation("获取AccessToken")
    @GetMapping("/access_token")
    public Result<AccessTokenRes.AccessTokenResData> getAccessToken(String openId) {
        AccessTokenRes.AccessTokenResData accessTokenResData = dyBasisService.getAuth2Service().authExchangeAccessToken(openId, ApiPlatform.DOU_YIN);
        return Result.success(accessTokenResData);
    }

    @ApiOperation("获取用户公开信息")
    @GetMapping("/open_info")
    public Result<UserOpenInfoRes.GetUserOpenInfoResData> getUserOpenInfo(String openId) {
        UserOpenInfoRes.GetUserOpenInfoResData userOpenInfo = dyBasisService.getUserManagerService().getUserOpenInfo(openId, ApiPlatform.DOU_YIN);
        return Result.success(userOpenInfo);
    }

    @ApiOperation("获取用户粉丝列表")
    @GetMapping("/fans")
    public Result<FansListRes.GetFansListResData> getFansList(String openId) {
        FansListRes.GetFansListResData fansList = dyBasisService.getUserManagerService().getFansList(openId, 0, new PageCount(10));
        return Result.success(fansList);
    }

    @ApiOperation("获取用户关注的人信息")
    @GetMapping("/following")
    public Result<FollowingListRes.GetFollowingListResData> getFollowingList(String openId) {
        FollowingListRes.GetFollowingListResData followingList = dyBasisService.getUserManagerService().getFollowingList(openId, 0, new PageCount(10));
        return Result.success(followingList);
    }

}